import sys

line1 = "@RG	ID:A	PL:illumina	PU:4290HAAXX090702.6    LB:Solexa-12789 DT:2009-07-02T00:00:00-0400     SM:TCGA-23-1032-10A-01W-0486-08 CN:BI"

readgrouphash = {}
outhash = {}
samcolumns = ["qname","flag","rname","pos","mapq","ciagr","mrnm","mpos","isize","seq","qual","opt"]
samcolumnslen = len(samcolumns)
print("len" + str(len(readgrouphash)))
readgroups = 1
read = {}
init = False
for j,term in enumerate(line1.split("\t")):
	if readgroups == 1:
        	if line1.startswith("@RG"):
                	if j == 1:
				rg = term.split(":")[1]
				#bucketFileName = "/titan/cancerregulome2/synthetic_cancer/trans_out_patient/" + prognosis + "/" + patientLabel + "_AllBinsSameChrom_500K"
				bucketFile = open("./out/" + rg, 'w')
				print("readgroup "+ rg +"\n")
				outhash["bucketFile" + rg] = bucketFile
                        	#if rg in readgroups:
                        	#                inRG = True
		if not line1.startswith("@"):
			init = True
                if j<samcolumnslen:
                	read[samcolumns[j]]=term
			print(str(j) + " " + samcolumns[j] + " " + term)
	else:
		print("no readgroups, outHash will contain one set of files")
		init = True

outhash["bucketFile" + rg].write("myfile written to hash");

for outh in outhash:
	outhash[outh].close()



